﻿

var customColumns = true;
fs.util.pageLoadFunction.push(function () {
    fs_maxWindow = true;
    firstColumns = [
              { index: 0, headerText: "Last Month", edit: true, reference: true, readonly: true, width: 80, rowText: "LM",
                  expression: function (row) {
                      return row[this.rowText] = getLastMonthFieldData(row.accountcode, "CM");
                  }
              },
              { index: 1, headerText: "Current Month", edit: true, readonly: true, width: 80, rowText: "CM" },
              { index: 7, headerText: "", edit: false, width: 80, rowText: "empty", readonly: true },

              { index: 2, headerText: "Not Due", edit: true, width: 80, rowText: "ND" },
              { index: 4, headerText: "0-15 Days", edit: true, width: 80, rowText: "D15" },
              { index: 5, headerText: "16-30 Days", edit: true, width: 80, rowText: "D30" },
              { index: 6, headerText: "31-60 Days", edit: true, width: 80, rowText: "D60" },
              { index: 8, headerText: "61-90 Days", edit: true, width: 80, rowText: "D90" },
              { index: 9, headerText: "91-150 Days", edit: true, width: 80, rowText: "D150" },
              { index: 10, headerText: ">150 Days", edit: true, width: 80, rowText: "G150" }
            ];

});

var rowAfterBinding = function (self) {
     
    self["CM"] = ko.computed(function () {
        return (parseFloat(unWarpValue(self['ND'])) + parseFloat(unWarpValue(self['D15'])) + parseFloat(unWarpValue(self['D30'])) + parseFloat(unWarpValue(self['D60'])) + parseFloat(unWarpValue(self['D90'])) + parseFloat(unWarpValue(self['D150'])) + parseFloat(unWarpValue(self['G150']))).toFix(self.digits); 
    });
}

var readyJSON = [
    { "accountcode": "AR02010100", "description": "Trade accounts receivable-gross", bold: true, datarow: true, index: 2, rowAfterBinding: rowAfterBinding,
        Process: [{
            Field: "All",
            Exp: {
                mode: "search",
                fields: ["AR02010101", "AR02010102", "AR02010103"],
                equ: "+"
            }
        }]
    },
    { "accountcode": "AR02010101", "description": "External", datarow: true, index: 1, rowAfterBinding: rowAfterBinding },
    { "accountcode": "AR02010102", "description": "Within Roquette Asia", "subrow": [], datarow: true, index: 1, rowAfterBinding: rowAfterBinding },
    { "emptyrow": true, description: "" },
    { "accountcode": "AR02010103", "description": "Within Roquette non-Asia", datarow: true, index: 1, rowAfterBinding: rowAfterBinding },
     { accountcode: "Control", description: "AR02010100=BS02010501", controlrow: true, index:3, Process: [
        {
            Field: "CM",
            Exp: {
                mode: "search",
                fields: ["AR02010100", "Refrence&Balance Sheet&CM_BS02010501"],
                equ: "-"
            }
        }]
    },

    { "emptyrow": true, description: "" },
    { "accountcode": "AR02010200", "description": "Interest receivable", bold: true, datarow: true, rowAfterBinding: rowAfterBinding,
        Process: [{
            Field: "All",
            Exp: {
                mode: "search",
                fields: ["AR02010201", "AR02010202", "AR02010203"],
                equ: "+"
            }
        }]
    },
    { "accountcode": "AR02010201", "description": "External", datarow: true, rowAfterBinding: rowAfterBinding },
    { "accountcode": "AR02010202", "description": "Within Roquette Asia", "subrow": [], datarow: true, rowAfterBinding: rowAfterBinding },
    { "emptyrow": true, description: "" },
    { "accountcode": "AR02010203", "description": "Within Roquette non-Asia", datarow: true, rowAfterBinding: rowAfterBinding },
     { accountcode: "Control", description: "AR02010200=BS02010700", controlrow: true, index: 2, Process: [
        {
            Field: "CM",
            Exp: {
                mode: "search",
                fields: ["AR02010200", "Refrence&Balance Sheet&CM_BS02010700"],
                equ: "-"
            }
        }]
    },

    { "emptyrow": true, description: "" },
    { "accountcode": "AP02010100", "description": "Trade accounts payable -gross", bold: true, datarow: true, rowAfterBinding: rowAfterBinding,
        Process: [{
            Field: "All",
            Exp: {
                mode: "search",
                fields: ["AP02010101", "AP02010102", "AP02010103"],
                equ: "+"
            }
        }]
    },
    { "accountcode": "AP02010101", "description": "External", datarow: true, rowAfterBinding: rowAfterBinding },
    { "accountcode": "AP02010102", "description": "Within Roquette Asia", "subrow": [], datarow: true, rowAfterBinding: rowAfterBinding },
    { "emptyrow": true, description: "" },
    { "accountcode": "AP02010103", "description": "Within Roquette non-Asia", datarow: true, rowAfterBinding: rowAfterBinding },
     { accountcode: "Control", description: "AP02010100=BS02020401", controlrow: true, index: 2, Process: [
        {
            Field: "CM",
            Exp: {
                mode: "search",
                fields: ["AP02010100", "Refrence&Balance Sheet&CM_BS02020401"],
                equ: "-"
            }
        }]
    },

    { "emptyrow": true, description: "" },
    { "accountcode": "AP02010200", "description": "Interest payable", bold: true, datarow: true, rowAfterBinding: rowAfterBinding,
        Process: [{
            Field: "All",
            Exp: {
                mode: "search",
                fields: ["AP02010201", "AP02010202", "AP02010203"],
                equ: "+"
            }
        }]
    },
    { "accountcode": "AP02010201", "description": "External", datarow: true, rowAfterBinding: rowAfterBinding },
    { "accountcode": "AP02010202", "description": "Within Roquette Asia", "subrow": [], datarow: true, rowAfterBinding: rowAfterBinding },
    { "emptyrow": true, description: "" },
    { "accountcode": "AP02010203", "description": "Within Roquette non-Asia", datarow: true, rowAfterBinding: rowAfterBinding },
    { accountcode: "Control", description: "AP02010200=BS02020600", controlrow: true, index: 2, Process: [
        { 
            Field: "CM",
            Exp: {
                mode: "search",
                fields: ["AP02010200", "Refrence&Balance Sheet&CM_BS02020601"],
                equ: "-"
            }
        }]
    },

    { "emptyrow": true, description: "" },
    { "accountcode": "AP02010300", "description": "Fixed assets payable", bold: true, datarow: true, rowAfterBinding: rowAfterBinding,
        Process: [{
            Field: "All",
            Exp: {
                mode: "search",
                fields: ["AP02010301", "AP02010302", "AP02010303"],
                equ: "+"
            }
        }]
    },
    { "accountcode": "AP02010301", "description": "External", datarow: true, rowAfterBinding: rowAfterBinding },
    { "accountcode": "AP02010302", "description": "Within Roquette Asia", "subrow": [], datarow: true, rowAfterBinding: rowAfterBinding },
    { "emptyrow": true, description: "" },
    { "accountcode": "AP02010303", "description": "Within Roquette non-Asia", datarow: true, rowAfterBinding: rowAfterBinding },
    { accountcode: "Control", description: "AP02010300=BS02020300", controlrow: true, index: 2, Process: [
        { 
            Field: "CM",
            Exp: {
                mode: "search",
                fields: ["AP02010300", "Refrence&Balance Sheet&CM_BS02020301"],
                equ: "-"
            }
        }]
    },


    { "emptyrow": true, description: "" },
    { "accountcode": "AR02010400", "description": "Other receivable", bold: true, datarow: true, rowAfterBinding: rowAfterBinding,
        Process: [{
            Field: "All",
            Exp: {
                mode: "search",
                fields: ["AR02010401", "AR02010402", "AR02010403"],
                equ: "+"
            }
        }]
    },
    { "accountcode": "AR02010401", "description": "External", datarow: true, rowAfterBinding: rowAfterBinding },
    { "accountcode": "AR02010402", "description": "Within Roquette Asia", "subrow": [], datarow: true, rowAfterBinding: rowAfterBinding },
    { "emptyrow": true, description: "" },
    { "accountcode": "AR02010403", "description": "Within Roquette non-Asia", datarow: true, rowAfterBinding: rowAfterBinding },
    { accountcode: "Control", description: "AR02010400=BS02010600+BS02010601", controlrow: true, index: 2, Process: [
        {
            Field: "CM",
            Exp: {
                mode: "search",
                fields: ["AR02010400", "Refrence&Balance Sheet&CM_BS02010600", "Refrence&Balance Sheet&CM_BS02010601"],
                equ: "-"
            }
        }]
    },


    { "emptyrow": true, description: "" },
    { "accountcode": "AP02010400", "description": "Other payable", bold: true, datarow: true, rowAfterBinding: rowAfterBinding,
        Process: [{
            Field: "All",
            Exp: {
                mode: "search",
                fields: ["AP02010401", "AP02010402", "AP02010403"],
                equ: "+"
            }
        }]
    }, 
    { "accountcode": "AP02010401", "description": "External", datarow: true, rowAfterBinding: rowAfterBinding },
    { "accountcode": "AP02010402", "description": "Within Roquette Asia", "subrow": [], datarow: true, rowAfterBinding: rowAfterBinding },
    { "emptyrow": true, description: "" },
    { "accountcode": "AP02010403", "description": "Within Roquette non-Asia", datarow: true, rowAfterBinding: rowAfterBinding },
    { accountcode: "Control", description: "AP02010400=BS02020500", controlrow: true, index: 2, Process: [
        {
            Field: "CM",
            Exp: {
                mode: "search",
                fields: ["AP02010400", "Refrence&Balance Sheet&CM_BS02020501"],
                equ: "-"
            }
        }]
    }

];